package com.ddwl.goods.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Slf4j
@Configuration
public class JobConfig {

    @Value("${ddwl.job.executor.appname}")
    private String appName;
    @Value("${ddwl.job.executor.port}")
    private int port;
    @Value("${ddwl.job.accessToken}")
    private String accessToken;
    @Value("${ddwl.job.admin.addresses}")
    private String addresses;
    @Value("${ddwl.job.executor.logpath}")
    private String logPath;
    @Value("${ddwl.job.executor.logretentiondays}")
    private int logRetentionDays;

    @Bean
    public XxlJobSpringExecutor jobExecutor(InetUtils inetUtils) {
        log.info(">>>>>>>>>>> job config init.");
        XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
        executor.setAdminAddresses(addresses);
        executor.setAppname(appName);
        executor.setIp(inetUtils.findFirstNonLoopbackHostInfo().getIpAddress());
        executor.setPort(-1);
        executor.setAccessToken(accessToken);
        executor.setLogPath(logPath);
        executor.setLogRetentionDays(logRetentionDays);
        return executor;
    }

}
